package b3.widget.home.town
{
	import b3.model.*;
	import b3.widget.guide.*;
	import b3.widget.basic.BasicButton;
	import b3.net.ResourceHelper;
	
	import flash.events.*;

	public class SocialDialog extends TalkDialog
	{
		private var clickCount:int;
		
		public function SocialDialog(buildingModel:BuildingModel)
		{
			var content:Array = new Array();
			for (var i:int = 0; i < buildingModel.socialInfos.length; i++)
			{
				var socialModel:SocialModel = buildingModel.socialInfos[i];
				var brief:String;
				if (socialModel.viewed == 1)
					continue;
				if (socialModel.type == 0)
				{
					brief = socialModel.userId + "帮你建设了这栋楼	" + "人口：" + socialModel.populationChange +"	高度" + socialModel.heightChange + "   也去他家帮助他建设吧";
				}
				else if (socialModel.type == 1)
				{
					brief = socialModel.userId + "帮你重建了这栋楼	" + "人口增加：" + socialModel.populationChange +"	高度变化" + socialModel.heightChange + "   也去他家帮助他建设吧";
				}
				else
				{
					brief = "建筑物遭到 " + socialModel.userId + " 攻击	" + "人口减少：" + (-socialModel.populationChange) +"	高度变化" + socialModel.heightChange + "   去他家攻击吧";
				}
				content.push(brief);
			}
			super("SocialDialogBgr", content);
			//下一条按钮
			var ButtonBgr1:Class = ResourceHelper.getInstance().getClassByName("ButtonBgr0");
			var buttonONext:BasicButton = new BasicButton(ButtonBgr1, "下一条");
//			buttonONext.addEventListener(MouseEvent.CLICK, super.onButtonOKClick);
			buttonONext.x = 160;
			buttonONext.y = 170;
			addChild(buttonONext);
			//关闭按钮	
			var ButtonBgr2:Class = ResourceHelper.getInstance().getClassByName("ButtonBgr0");
			var buttonClose:BasicButton = new BasicButton(ButtonBgr2, "关闭");
			buttonClose.addEventListener(MouseEvent.CLICK, onStageMouseClick);
			buttonClose.x = 40;
			buttonClose.y = 170;
			addChild(buttonClose);
			
			addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
		}
		
		private function onAddedToStage(event:Event):void
		{
			clickCount = 0;
			stage.addEventListener(MouseEvent.CLICK, onStageMouseClick);
		}
		
		private function onStageMouseClick(event:Event):void
		{
			if (clickCount-- < 0)
				close();
		}
		
		
	}
}